package cn.oa.service.impl;


import cn.oa.dao.PositionDao;
import cn.oa.entity.Position;
import cn.oa.service.PositionService;
import cn.oa.util.SessionFatoryUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;

/**
 * @Description TODO
 * @Author hyl
 * @Date 2022/3/29 9:06
 **/
public class PositionServiceImpl implements PositionService {

	@Override
	public List<Position> getAllPositions() throws SQLException, IOException {
		String resource="mybatis-config.xml";
		InputStream is= Resources.getResourceAsStream(resource);
		SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(is);
		SqlSession sqlSession=sessionFactory.openSession();

		PositionDao dao=sqlSession.getMapper(PositionDao.class);
		List<Position> list=dao.getAllPositions();
		sqlSession.close();
		return list;
	}
}
